package cn.sw.file.config;
 
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Configuration
public class MinioConfig {

    @Resource
    private MinIOConfigInfo minIOConfigInfo;

    @Bean
    public MinioClient minioClient() {
        System.out.println("\n--------------- ------------------------------------------------------ ---------------\n");
        System.out.println("\n--------------- MinIO 服务连接成功 ---------------\n");
        System.out.println("\n--------------- MinIO 服务地址:"+minIOConfigInfo.getEndpoint()+" ---------------\n");
        System.out.println("\n--------------- MinIO 用户名："+minIOConfigInfo.getAccessKey()+" ---------------\n");
        System.out.println("\n--------------- MinIO 密码："+minIOConfigInfo.getSecretKey()+" ---------------\n");
        System.out.println("\n--------------- MinIO 默认存储桶："+minIOConfigInfo.getBucketName()+" ---------------\n");
        System.out.println("\n--------------- ------------------------------------------------------ ---------------\n");
        //链式编程，构建MinioClient对象
        return MinioClient.builder()
                .endpoint(minIOConfigInfo.getEndpoint())
                .credentials(minIOConfigInfo.getAccessKey(), minIOConfigInfo.getSecretKey())
                .build();
    }
}